make qstarz format dynamic (#1212)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 9 Nov 2023 15:00:03 +0000 (08:00 -0700)
committerGitHub <noreply@github.com>
Thu, 9 Nov 2023 15:00:03 +0000 (08:00 -0700)
qstarz_bl_1000.cc
qstarz_bl_1000.h
vecs.cc

index 2910a4ab1a77e53886773b3a0a3eb84bc925d7f3..a0aadce00673b8cc14332267d2b5a9ed2834ef98 100644 (file)
@@ -135,7 +135,7 @@ QstarzBL1000Format::qstarz_bl_1000_read_record(QDataStream& stream, route_head*
   stream >> unused2;
 
   if (stream.status() != QDataStream::Ok) {
-    fatal(FatalMsg() << MYNAME << ": File format error on " << read_fname << ". Perhaps this isn't a Qstarz BL-1000 file");
+    fatal(FatalMsg() << MYNAME << ": File format error on " << fname << ". Perhaps this isn't a Qstarz BL-1000 file");
   }
 
   BL1000_POINT_TYPE type;
@@ -171,7 +171,7 @@ QstarzBL1000Format::qstarz_bl_1000_read_record(QDataStream& stream, route_head*
   default:
     type = BL1000_POINT_TYPE_UNKNOWN;
 
-    fatal(FatalMsg() << MYNAME << ": File format error on " << read_fname << ". Unexpected value for RCR (record reason): " << rcr);
+    fatal(FatalMsg() << MYNAME << ": File format error on " << fname << ". Unexpected value for RCR (record reason): " << rcr);
 
     break;
   }
@@ -205,7 +205,7 @@ QstarzBL1000Format::qstarz_bl_1000_read_record(QDataStream& stream, route_head*
     fix = fix_unknown;
 
     if (type != BL1000_POINT_TYPE_UNKNOWN) {
-      fatal(FatalMsg() << MYNAME << ": File format error on " << read_fname << ". Unexpected value for fix quality: " << fixQuality);
+      fatal(FatalMsg() << MYNAME << ": File format error on " << fname << ". Unexpected value for fix quality: " << fixQuality);
     }
 
     break;
@@ -219,11 +219,11 @@ QstarzBL1000Format::qstarz_bl_1000_read_record(QDataStream& stream, route_head*
   // qDebug(waypoint)
 
   if ((waypoint->latitude < -90) || (waypoint->latitude > 90)) {
-    fatal(FatalMsg() << MYNAME << ": File format error on " << read_fname << ". Unexpected value for latitude: " << waypoint->latitude);
+    fatal(FatalMsg() << MYNAME << ": File format error on " << fname << ". Unexpected value for latitude: " << waypoint->latitude);
   }
 
   if ((waypoint->longitude < -180) || (waypoint->longitude > 180)) {
-    fatal(FatalMsg() << MYNAME << ": File format error on " << read_fname << ". Unexpected value for longitude: " << waypoint->longitude);
+    fatal(FatalMsg() << MYNAME << ": File format error on " << fname << ". Unexpected value for longitude: " << waypoint->longitude);
   }
 
   waypoint->altitude = altitude;
@@ -268,24 +268,12 @@ QstarzBL1000Format::qstarz_bl_1000_read_record(QDataStream& stream, route_head*
  *              entry points called by gpsbabel main process               *
  ***************************************************************************/
 
-void
-QstarzBL1000Format::rd_init(const QString& fname)
-{
-  read_fname = fname;
-}
-
-void
-QstarzBL1000Format::rd_deinit()
-{
-  read_fname.clear();
-}
-
 void
 QstarzBL1000Format::read()
 {
-  QFile file(read_fname);
+  QFile file(fname);
   if (!file.open(QIODevice::ReadOnly)) {
-    fatal(FatalMsg() << MYNAME << ": Error opening file " << read_fname);
+    fatal(FatalMsg() << MYNAME << ": Error opening file " << fname);
   }
 
   QDataStream stream(&file);
index 2870407e9bea469ef1b0f8de10360599819eeac8..2a52c4b9d95308c902dec51133fdccbbb2681132 100644 (file)
@@ -55,6 +55,8 @@ struct qstarz_bl_1000_fsdata : FormatSpecificData {
 class QstarzBL1000Format : public Format
 {
 public:
+  using Format::Format;
+
   ff_type get_type() const override
   {
     return ff_type_file;
@@ -69,15 +71,9 @@ public:
     };
   }
 
-  void rd_init(const QString& fname) override;
+  void rd_init(const QString& fname) override {}
   void read() override;
-  void rd_deinit() override;
   void qstarz_bl_1000_read(QDataStream& stream);
   void qstarz_bl_1000_read_record(QDataStream& stream, route_head* track_route);
-
-private:
-  QString read_fname;
 };
-
-
 #endif
diff --git a/vecs.cc b/vecs.cc
index 75238c8fc9559603dfcb3dc3dc9305d837b801df..c4c7a7a995b4f2968a744b10f2d57573f1d58e81 100644 (file)
--- a/vecs.cc
+++ b/vecs.cc
@@ -162,7 +162,6 @@ struct Vecs::Impl {
   GarminFitFormat format_fit_fmt;
   GeoJsonFormat geojson_fmt;
   GlobalsatSportFormat globalsat_sport_fmt;
-  QstarzBL1000Format qstarz_bl_1000_fmt;
 #endif // MAXIMAL_ENABLED
 
   const QVector<vecs_t> vec_list {
@@ -488,11 +487,12 @@ struct Vecs::Impl {
       nullptr,
     },
     {
-      &qstarz_bl_1000_fmt,
+      nullptr,
       "qstarz_bl-1000",
       "Qstarz BL-1000",
       nullptr,
       nullptr,
+      &fmtfactory<QstarzBL1000Format>
     },
     {
       nullptr,